package com.itheima.controller;


import com.itheima.pojo.UmsResourceCategory;
import com.itheima.service.UmsResourceCategoryService;
import com.itheima.vo.PageResultVo;
import com.itheima.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("resourceCategory")
public class UmsResourceCategoryController {


    @Autowired
    private UmsResourceCategoryService umsResourceCategoryService;

    /**
     * 添加后台资源分类
     * @param umsResourceCategory
     * @return
     */
    @PostMapping("create")
    public Result save(@RequestBody UmsResourceCategory umsResourceCategory){
        umsResourceCategoryService.add(umsResourceCategory);
        return Result.success(null);
    }

    /**
     * 根据ID删除后台资源
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    public Result deleteById(@PathVariable("id") Integer id){
        umsResourceCategoryService.deleteByIds(id);
        return Result.success(null);
    }

    /**
     * 查询所有后台资源分类
     * @return
     */
    @GetMapping("/listAll")
    public Result findAll(){
        List<UmsResourceCategory> list= umsResourceCategoryService.findAll();
        return Result.success(list);
    }

    /**
     * 修改后台资源分类
     * @param umsResourceCategory
     * @return
     */
    @PostMapping("update/{id}")
    public Result updateById(@PathVariable("id")Integer id,@RequestBody UmsResourceCategory umsResourceCategory){
        umsResourceCategoryService.update(id,umsResourceCategory);
        return Result.success(null);
    }
}
